package zut.cs.liziflower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import zut.cs.liziflower.entity.Order;
import zut.cs.liziflower.mapper.OrderMapper;
import zut.cs.liziflower.service.IOrderService;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xuwenke
 * @since 2022-05-26
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Resource
    private OrderMapper orderMapper;

    @Override
    public int addOrder(Order order) {
        return orderMapper.addOrder(order.getUserid(), order.getAddressid(), order.getTotalprice()
                , order.getMessage(), order.getStatus());
    }

    @Override
    public Order getOrder(Order order) {
        return orderMapper.getOrder(order.getUserid(), order.getAddressid(), order.getTotalprice(),
                order.getMessage(), order.getStatus());

    }

    @Override
    public List<Order> getAllPaidOrders(Integer userid, Integer status) {
        List<Order> list = orderMapper.getAllPaidOrders(userid, status);
        return list;
    }

    @Override
    public int updateStatus(Order order) {

        return orderMapper.updateStatus(order.getOrderid(), order.getUserid());

    }

    @Override
    public int updatedFinished(Integer orderid, Integer userid, Integer status) {
        return orderMapper.updatedFinished(orderid, userid, status);
    }

    @Override
    public int deletePaid(Integer orderid, Integer userid) {
//        QueryWrapper<Order> wrapper = new QueryWrapper<>();
//        wrapper.eq("orderid", orderid).and(q -> q.eq("userid", userid));
        return orderMapper.deletePaid(orderid,userid);
    }
}
